package com.mojito.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.List;

/**
 * @author liufq
 * @since 2020-10-25 10:22:30
 */
@Data
@AllArgsConstructor
public class Pager<T> {

    /**
     * 总数量
     */
    private Long total;

    /**
     * 分页数据
     */
    private List<T> records;

    /**
     * 转换分页结果
     */
    public static <T> Pager<T> transform(Page<?> data, Class<T> clazz) {
        return new Pager<>(data.getTotal(), BaseHelper.r2t(data.getRecords(), clazz));
    }

    /**
     * 获取分页入参
     */
    public static <T> Page<T> getPage(PageRequest request) {
        return new Page<>(request.getPageNo(), request.getPageSize(), request.getPageSize());
    }
}
